package helper
import (
    "fmt"
    "io/ioutil"
    "runtime"
    "path"
    "log"
    "encoding/json"
)
type Config struct {
    ListenAddr string
    Storage string
}
var Conf Config

func LoadConf(){
    const dataFile = "config.json"
    //当前运行目录
    _, filename, _, _ := runtime.Caller(1)
    datapath := path.Join(path.Dir(filename), dataFile)
    //fmt.Println(datapath)
    if contents,err := ioutil.ReadFile(datapath);err != nil {
        log.Fatalln(err)
        return;
    }else {
        err := json.Unmarshal(contents, &Conf)
        if err != nil {
            fmt.Println("读取配置失败:", err)
            return
        }
    }
    /*b := []byte(`{"ListenAddr": "0.0.0.0:10086", "Storage": "E:/image/storage"}`)
    err1 := json.Unmarshal(b, &Conf)
    if err1 != nil {
        fmt.Println("读取配置失败:", err1)
        return
    }*/
}